/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ing.sisval.da;

import java.sql.Connection;
import java.util.ArrayList;
import org.ing.sisval.be.BEContenedorComplementario;
import org.rx.cr.dao.DAOAbstract;

/**
 *
 * @author Mysham
 */
public class DAContenedorComplementario extends DAOAbstract<BEContenedorComplementario> {

    public DAContenedorComplementario(Connection conn) {
        setConnection(conn);
    }

    @Override
    public int registrar(BEContenedorComplementario be) throws Exception {
        try {
            setStoreProcedure("SISVAL.sp_ins_contenedorcomplementario");
            setParameterInt(be.getPropiedadid());
            setParameterInt(be.getValuacioncomplementarioid());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int actualizarRegistro(BEContenedorComplementario be) throws Exception {
        try {
            setStoreProcedure("SISVAL.sp_upd_contenedorcomplementario");
            setParameterInt(be.getContenedorcomplementarioid());
            setParameterInt(be.getPropiedadid());
            setParameterInt(be.getValuacioncomplementarioid());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int eliminarRegistro(BEContenedorComplementario be) throws Exception {
        try {
            setStoreProcedure("SISVAL.sp_del_contenedorcomplementario");
            setParameterInt(be.getContenedorcomplementarioid());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public ArrayList<BEContenedorComplementario> buscarReferencia(String string) throws Exception {
        try {
            clear();
            setStoreProcedure("SISVAL.sp_sel_contenedorcomplementario");
            setParameterString(string);
            commitc();
            while (existResult()) {
                BEContenedorComplementario be = new BEContenedorComplementario();
                be.setContenedorcomplementarioid(getDataInt(1));
                be.setPropiedadid(getDataInt(2));
                be.setValuacioncomplementarioid(getDataInt(3));

                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public ArrayList<BEContenedorComplementario> listar() throws Exception {
        try {
            clear();
            setStoreProcedure("SISVAL.sp_sel_contenedorcomplementario");
            setParameterString("");
            commitc();
            while (existResult()) {
                BEContenedorComplementario be = new BEContenedorComplementario();
                be.setContenedorcomplementarioid(getDataInt(1));
                be.setPropiedadid(getDataInt(2));
                be.setValuacioncomplementarioid(getDataInt(3));

                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public BEContenedorComplementario buscar(int i) throws Exception {
        try {
            BEContenedorComplementario be = null;
            setStoreProcedure("SISVAL.sp_sel_contenedorcomplementario_id");
            setParameterString("");
            commitc();
            while (existResult()) {
                be = new BEContenedorComplementario();
                be.setContenedorcomplementarioid(getDataInt(1));
                be.setPropiedadid(getDataInt(2));
                be.setValuacioncomplementarioid(getDataInt(3));

                add(be);
            }
            return be;
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    public ArrayList<BEContenedorComplementario> listarAsignacion(int idvc) {
        try {
            clear();
            setStoreProcedure("sp_sel_asignacion_contenedorcomplementario");
            setParameterInt(idvc);
            commitc();
            while (existResult()) {
                BEContenedorComplementario be = new BEContenedorComplementario();
                be.setContenedorcomplementarioid(getDataInt(1));
                be.setPropiedadid(getDataInt(2));
                be.setValuacioncomplementarioid(getDataInt(3));
                add(be);

            }
            return getLista();

        } catch (Exception e) {
            try {
                rollback(e);
            } catch (Exception ex) {
            }
            return null;
        }
    }
    
    public int eliminarAsignacion(int idet) throws Exception {
        try {
            setStoreProcedure("sp_del_contenedorcomplementario");
            setParameterInt(idet);
            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }
    

}
